package com.py.credit.controller;

import com.py.credit.common.rest.RestServiceResult;
import com.py.credit.constant.ConstantData;
import com.py.credit.service.ImmediatePerService;
import com.py.credit.utils.DateCheckUtils;
import com.py.framework.core.annotation.IgnoreAuthority;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "/immediate")
public class ImmediatePerController {

    @Autowired
    private ImmediatePerService immediatePerService;

    @IgnoreAuthority
    @RequestMapping(value = "/checkImmediatePer.do")
    public RestServiceResult<Object> checkImmediatePer() {
        RestServiceResult<Object> r = new RestServiceResult<>();
        try {
            //远程获取工作日信息
            List<Map<String, Object>> dateList = immediatePerService.getDateInfo().getData();
            //获取双公示信息
            List<Map<String, Object>> FrCf = immediatePerService.getInfoByFrCf();
            List<Map<String, Object>> FrXk = immediatePerService.getInfoByFrXk();
            List<Map<String, Object>> ZrrCf = immediatePerService.getInfoByZrrCf();
            List<Map<String, Object>> ZrrXk = immediatePerService.getInfoByZrrXk();
            immediatePerService.updateTableImmePer(DateCheckUtils.sgsDateCheck(FrCf, dateList, ConstantData.FRCF, ConstantData.CF), ConstantData.FRCF);
            immediatePerService.updateTableImmePer(DateCheckUtils.sgsDateCheck(FrXk, dateList, ConstantData.FRXK, ConstantData.XK), ConstantData.FRXK);
            immediatePerService.updateTableImmePer(DateCheckUtils.sgsDateCheck(ZrrCf, dateList, ConstantData.ZRRCF, ConstantData.CF), ConstantData.ZRRCF);
            immediatePerService.updateTableImmePer(DateCheckUtils.sgsDateCheck(ZrrXk, dateList, ConstantData.ZRRXK, ConstantData.XK), ConstantData.ZRRXK);
            r.setMsg("计算及时率的定时任务运行成功！");
        } catch (ParseException e) {
            r.setCode(RestServiceResult.CODE_UNKNOW);
            r.setMsg("计算及时率的定时任务运行失败！");
        }
        return r;
    }
}
